# hnol_rss.sh now incorporates horizontal/vertical judging and resizing&zip function all in one!
# dependency: GNU wget (busybox wget cannot work); imagicmagick for mogrify  
wget -O index_hnol_rss.htm http://bbs.voc.com.cn/rss.php?fid=50
cat index_hnol_rss.htm | grep link | grep topic > links_hnol_rss.htm
sed -i -e "s/<link>//g" links_hnol_rss.htm 
sed -i -e "s/<\/link>//g" links_hnol_rss.htm 
sed -i -e "s/\ *//g" links_hnol_rss.htm
sed -i -e "s/topic/archiver\/tid/g" links_hnol_rss.htm 
sed -i -e "s/-[0-9]-[0-9]//g" links_hnol_rss.htm

wget -nd -r -Dimage.hnol.net,bbs.voc.com.cn -l1 -A jpg -H -i links_hnol_rss.htm

#identify_jpg_hori_vert_resize embeded here to make it portable (run within 1 dir, any dir)
rm -f hnol_rss*.zip

find . -name "*.jpg" | while read jpgfilename; do
    xsize=`identify -ping $jpgfilename | sed -e "s/.*JPEG //g" | sed -e "s/x.*//g"`
    ysize=`identify -ping $jpgfilename | sed -e "s/.*JPEG [0-9]*x//g" | sed -e "s/\ [0-9]*x.*//g"`

    if [ $xsize -ge $ysize ] ; then
	if [ $xsize -ge 500 ] ; then
        	mogrify -resize 480x320 $jpgfilename
    	fi
    	zip ./hnol_rss_hori.zip $jpgfilename >/dev/null;
    else 
    	if [ $ysize -ge 500 ] ; then
        	mogrify -resize 320x480 $jpgfilename
    	fi
    	zip ./hnol_rss_vert.zip $jpgfilename >/dev/null;
    fi
done

rm -f *.jpg
#/identify_jpg_hori_vert_resize embeded here to make it portable (run in 1 dir, any dir)

